#!/bin/bash
. ./cmd.sh
. ./path.sh

mfccdir=mfcc
stage=3
numGauss=128
ivecDim=25

if [ $stage -le 0 ]; then

for x in train dev test; do
  steps/make_mfcc.sh --cmd "$train_cmd" --nj 5 data/mfcc_features/$x exp/make_mfcc/$x $mfccdir
  steps/compute_cmvn_stats.sh data/mfcc_features/$x exp/make_mfcc/mfcc_features/$x $mfccdir
done

#vocal activity detection
sid/compute_vad_decision.sh --nj 5 --cmd "$train_cmd" data/mfcc_features/train exp/make_vad $mfccdir
sid/compute_vad_decision.sh --nj 5 --cmd "$train_cmd" data/mfcc_features/dev exp/make_vad $mfccdir
sid/compute_vad_decision.sh --nj 5 --cmd "$train_cmd" data/mfcc_features/test exp/make_vad $mfccdir
fi


if [ $stage -le 1 ]; then
sid/train_diag_ubm.sh --nj 5 --cmd "$train_cmd" data/mfcc_features/train $numGauss \
    exp/diag_ubm_${numGauss}

sid/train_full_ubm.sh --nj 5 --cmd "$train_cmd" data/mfcc_features/train \
    exp/diag_ubm_${numGauss} exp/full_ubm_${numGauss}

fi

if [ $stage -le 2 ]; then
sid/train_ivector_extractor.sh --cmd "$train_cmd" --ivector_dim $ivecDim \
  --num-iters 5 exp/full_ubm_${numGauss}/final.ubm data/mfcc_features/train exp/extractor_${numGauss}_${ivecDim}
fi


if [ $stage -le 3 ]; then
# Extract the iVectors for the training data.
sid/extract_ivectors.sh --cmd "$train_cmd" --nj 5 \
   exp/extractor_${numGauss}_${ivecDim} data/mfcc_features/train exp/ivectors_train_${numGauss}_${ivecDim}


sid/extract_ivectors.sh --cmd "$train_cmd" --nj 5 \
   exp/extractor_${numGauss}_${ivecDim} data/mfcc_features/dev exp/ivectors_dev_${numGauss}_${ivecDim}


sid/extract_ivectors.sh --cmd "$train_cmd" --nj 5 \
   exp/extractor_${numGauss}_${ivecDim} data/mfcc_features/test exp/ivectors_test_${numGauss}_${ivecDim}

fi
